#!/bin/bash
#scription:

# define variables 
base_dir=/application/mysql
backupdir=/application/backup
timestamp=`date +%F`
user=root
password='123'
socket=${base_dir}/mysql.sock
#rsync_ip=168.204.37.25

# get databases list
DBlist=(
radius
mysql
syslog
)

# create directory
[ -e $backupdir ] || mkdir $backupdir


# backup for every database

for db in ${DBlist[@]}
do
${base_dir}/bin/mysqldump -B $db -u${user} -p${password} -S ${socket} --master-data=2 --single-transaction|gzip >${backupdir}/${db}_${timestamp}.gz 
#mysqldump -B $db -u${user} -S ${socket} --master-data=2 --single-transaction --routines --triggers|gzip >${backupdir}/${db}_${timestamp}.gz 
#check md5 
md5sum ${backupdir}/${db}_${timestamp}.gz >${backupdir}/${db}_${timestamp}.md5
done


#rsync 
# rsync binlog every one seconds

# delete +7 days ago data
find ${backupdir} -type f -name *.gz -ctime +7|xargs rm -f >/dev/null 2>&1
